from manim import *



class math2(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])


          #镜头跟进效果
        self.camera.frame.save_state()
        text0=Text("伪奇偶性",color=PINK).scale(5.0).move_to([0,0,0])
        self.play(Create(text0),FadeIn(dot1),FadeIn(dot2),FadeIn(dot3),self.camera.frame.animate.scale(0.6).move_to([0,0,0])) 
        self.wait()
        #镜头拉回
        self.play(Restore(self.camera.frame))
         #中心主题+框框标记
        text1 = Tex(r"\text{伪奇偶性}",color=PINK
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,5,0])
        self.play(
            ReplacementTransform(text0,text1)
        )
        self.wait(0.5)
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=13,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-30, 5, 0])
        self.play(Create(rectangle))
        #箭头引出
        arrow = Arrow(start=[-22,7.5,0],end=[-15,15,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))
        #文本2
        text2 = Tex(r"$f\left( -\sin x\right) =-f\left( \sin x\right) $\text{ 如  }$\int \dfrac{\sin x}{1+\cos ^{2}x}dx$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,15,0])
        self.play(Write(text2))
        text6 = Tex(r"\text{凑}$d\left( \cos x\right)$ ",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text2,RIGHT,buff=1)
        self.play(Write(text6))
        #箭头1引出
        arrow1 = Arrow(start=[-22,5,0],end=[-15,5,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow1))
        #文本3
        text3 = Tex(r"$f\left( -\cos x\right) =-f\left( \cos x\right) $\text{ 如 }$\int \dfrac{\cos x}{1+\sin ^{2}x}dx$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,5,0])
        self.play(Write(text3))
        text7 = Tex(r"\text{凑}$d\left( \sin x\right) $ ",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text3,RIGHT,buff=1)
        self.play(Write(text7))
        #箭头2引出
        arrow2 = Arrow(start=[-22,2.5,0],end=[-15,-5,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow2))
        #文本4
        text4 = Tex(r"$f\left( -\sin x,-\cos x\right) =f\left( \sin x,\cos x\right) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-5,0])
        self.play(Write(text4))

        text5 = Tex(r"\text{ 如 }$\int \dfrac{1}{1+\sin ^{2}x}dx$\text{ , }$\int \dfrac{\sin x\cos x}{\sin ^{4}x+\cos ^{4}x}dx$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,-10,0])
        self.play(Write(text5))
        text8 = Tex(r"\text{凑}$d\left( \tan x\right)  $ ",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text4,RIGHT,buff=1)
        self.play(Write(text8))
        

        #框框标记

        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([25, 15, 0])
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.move_to([25, 5, 0])
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.0,width=35,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle3.move_to([10, -10, 0])
        self.play(Create(rectangle3),Create(rectangle1),Create(rectangle2))





